import req from '@/utils/request';
import * as URL from '@/constants/api';

// 获取特定一条新闻详情
export function getArticleContent(id) {
  return req({
    url: URL.ARTICLE_ITEM + id,
  })
    .then(res => res.data.data);
}
// 获取评论列表
export function getCommentList(id) {
  return req({
    url: URL.COMMENT_LIST,
    params: {
      type: 'a',
      source: id,
    }
  })
    .then(res => res.data?.data.results);
}
// 获取回复评论列表
export function getReplyCommentList(id) {
  return req({
    url: URL.COMMENT_LIST,
    params: {
      type: 'c',
      source: id,
    }
  })
    .then(res => res.data?.data.results);
}
// 关注作者
export function followAuthor(id) {
  return req({
    url: URL.FOLLOW_AUTHOR,
    method: 'POST',
    data: {
      target: id,
    }
  })
    .then(res => res.data.message);
}
// 取消关注作者
export function cancelFollowAuthor(id) {
  return req({
    url: URL.CANCEL_FOLLOW_AUTHOR + id,
    method: 'DELETE',
  })
    .then(res => res.data.message || '取消关注成功');
}
// 收藏文章
export function articleCollect(id) {
  return req({
    url: URL.COLLECT_ARTICLE,
    method: 'POST',
    data: {
      target: id,
    }
  })
    .then(res => res.data.message);
}
// 取消收藏文章
export function cancelArticleCollect(id) {
  return req({
    url: URL.CANCEL_COLLECT_ARTICLE + id,
    method: 'DELETE',
  })
    .then(res => res.data.message || "取消收藏成功");
}
// 对文章点赞
export function toLikeArticle(id) {
  return req({
    url: URL.LIKE_ARTICLE,
    method: 'POST',
    data: {
      target: id,
    }
  })
    .then(res => res.data.message);
}
// 取消对文章点赞
export function cancelLikeArticle(id) {
  return req({
    url: URL.CONCEL_LIKE_ARTICLE + id,
    method: 'DELETE',
  })
    .then(res => res.data.message || "取消点赞成功");
}
// 对评论点赞
export function toLikeComment(id) {
  return req({
    url: URL.COMMENT_LIKE,
    method: 'POST',
    data: {
      target: id,
    }
  })
    .then(res => res.data.message);
}
// 取消对评论点赞
export function cancelLikeComment(id) {
  return req({
    url: URL.CANCEL_COMMENT_LIKE + id,
    method: 'DELETE',
  })
    .then(res => res.data.message || "取消点赞成功");
}
// 对文章进行评论
export function commentArticle(id, value) {
  return req({
    url: URL.COMMENT_LIST,
    method: 'POST',
    data: {
      target: id,
      content: value,
    }
  })
    .then(res => res);
}
